﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Windows.Forms;
using NIKE_Project.DAL;

namespace NIKE_Project.BLL
{
    public class WarehousingService
    {
        DBHelper db = new DBHelper();
        public DataSet ReadInfo(string Dq)
        {
            string SQl = string.Format("select * from Goods,Type where Goods.TypeID=Type.TypeID and BarCode='{0}'", Dq);
            DataSet ds = db.getDataSet(SQl);
            return ds;
        }
        public int EnterStorage(string BarCode, string TypeID, string GoodsName, string StorePrice, string SalePrice, string Discount, string StockNum)
        {
            //添加商品SQL语句
            string Sql = string.Format(@"insert into Goods(BarCode,TypeID,GoodsName,StorePrice,SalePrice,Discount,StockNum) values
				 ('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", BarCode, TypeID, GoodsName, StorePrice, SalePrice, Discount, StockNum);
            int rows = db.zsg(Sql);
            return rows;
        }
        public int UpdateStorage(string TypeID, string GoodsName, string StorePrice, string SalePrice, string Discount, string StockNum, string BarCode) 
        {
            string SqlStr = string.Format(@"update Goods set TypeID='{0}',GoodsName='{1}',StorePrice='{2}',SalePrice='{3}',Discount='{4}',StockNum=StockNum+{5} 
                                              where BarCode='{6}'", TypeID, GoodsName, StorePrice, SalePrice, Discount, StockNum, BarCode);
            int Rows = db.zsg(SqlStr);
            return Rows;
        }
        public int DeleteStorage(string st)
        {   
            //更新库存SQL语句
            string SqlStr = string.Format("delete from Goods where BarCode = '{0}'", st);
            int Rows = db.zsg(SqlStr);
            return Rows;

        }
        public DataSet WarehouseLoad()
        {
            string Sql = string.Format("select TypeName,ParentID from Type where TypeName in('鞋类','服装','户外装备')");
            DataSet ds = db.getDataSet(Sql);
            return ds;
        }
    }
}
